/**
 * Button组件
 * @class Button
 * @extends Basic
 *
 * @param value 显示内容
 * @param [herf] 有传时为链接按钮，没有onClick，onMouseDown参数
 * @param {function} onMouseDown 鼠标按下时触发
 * @param {function} onClick 点击时触发
 *
 * 示例:
 *
 *     @example
 *     <Button value="提交" onClick={this.onclick}/>
 *
 *
 */
var Button = React.createClass({
	getInitialState:function () {
		return{
			disabled:this.props.disabled || false
		}
    },
	getDefaultProps:function(){
		return{
			// disabled:false
		}
	},
	_handler:function(){
		var _this = this;
        this.props.onClick();
	},
	render: function() {
		var _this = this;
		if(this.props.dmbind){
            GiraffObjectManager[this.props.dmbind].setDisabled = function(bool){
                if(bool){
                    _this.setState({
                        disabled:true
                    })
                }else{
                    _this.setState({
                        disabled:false
                    })
                }
            };
		}

        var customClassName = this.props.className ? 'ucs-btn '+this.props.className : 'ucs-btn';
        customClassName = this.state.disabled ? customClassName + " ucs-btn-disabled" : customClassName;
		var id = this.props.id?this.props.id:'';
		if(this.props.href){
			return <a id={id} onClick={this.props.onClick} className={customClassName} href={this.props.href}>{this.props.value}</a>
		}else{
			return <button id={id} disabled={this.state.disabled} onClick={this._handler.bind(this)} onMouseDown={this.props.onMouseDown} className={customClassName}>{this.props.value}</button>
		}
	}
})
module.exports = Button;